import { request, uploadFile } from '@/utils/request'

/**
 * 获取验证码
 */
export const getCodeApi = (phone) => {
  return request({
    method: 'get',
    url: '/portal/user/send_code',
    data: {
      phone
    }
  })
}
/**
 * 验证码登录
 */
export const loginByCodeApi = ({ phone, code }) => {
  return request({
    url: '/portal/user/login/code',
    method: 'post',
    data: {
      phone,
      code
    }
  })
}

/**
 * 微信一键登录
 */
export const loginByWxApi = (openId) => {
  return request({
    method: 'post',
    url: '/portal/user/login/wechat',
    data: {
      openId
    }
  })
}

/**
 * 退出登录
 */
export const logoutApi = () => {
  return request({
    method: 'delete',
    url: '/portal/user/logout'
  })
}

/**
 * 获取用户信息
 */
export const getUserProfileApi = () => {
  return request({
    method: 'get',
    url: '/portal/user/login_info/get'
  })
}

/**
 * 上传头像至OSS
 */
export const uploadImage2OssApi = ({ key, filePath }) => {
  return uploadFile({
    url: '/file/upload',
    key,
    filePath
  })
}

/**
 * 编辑资料
 */
export const putUserProfileApi = ({ userId, avatar, nickName }) => {
  return request({
    url: '/portal/user/edit',
    method: 'post',
    data: {
      userId,
      avatar,
      nickName
    }
  })
}
